<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta charset='utf-8' />
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <title>开挖分析</title>
    <!--引入第三方的jquery脚本库-->
    <script include="jquery" src="./static/libs/include-lib-local.js"></script>
    <script src="./static/libs/include-cesium-local.js"></script>
    <!--当前示例页面样式表引用-->
    <link rel="stylesheet" href="./static/demo/cesium/style.css" />
    <script>
        var webGlobe, viewer;
        //定义三维瓦片类
        var tileset;
        //动态开挖对象
        var dynaCut;
        var distance = 30;
        //地图初始化函数
        function init() {
            //构造三维视图类（视图容器div的id，三维视图设置参数）
            webGlobe = new Cesium.WebSceneControl('GlobeView', {
                terrainExaggeration: 1,
            });
            //设置地下模式
            webGlobe.viewer.scene.globe.undergroundMode = true;
            //大气显示
            webGlobe.viewer.scene.skyAtmosphere.show = false;
            //大气显示
            webGlobe.viewer.scene.skyAtmosphere.showGroundAtmosphere = false;
            //透明度
            webGlobe.viewer.scene.globe.enableTransparent = true;
            webGlobe.viewer.scene.globe.transparent = 0.0;
            webGlobe.viewer.scene.globe.baseColor = new Cesium.Color(0, 0, 0, 0.00001);
            //开启深度检测
            webGlobe.viewer.scene.globe.depthTestAgainstTerrain = true;
            //初始化视图功能管理类
            var sceneManager = new CesiumZondy.Manager.SceneManager({
                viewer: webGlobe.viewer
            });
            //视点跳转
            sceneManager.flyToEx(112.94845170512113, 30.004246325952618, {
                height: 2600,
                heading: 67,
                pitch: -30,
                roll: 0
            });
            //构造M3D模型层管理对象
            var m3dLayer = new CesiumZondy.Layer.M3DLayer({
                viewer: webGlobe.viewer
            });
            var { protocol, ip, port } = window.webclient;
            var drilllayer = m3dLayer.append(
                `${protocol}://${ip}:${port}/igs/rest/g3d/钻孔_2_钻孔模型s`, {
                autoReset: false,
            }
            );
            //加载M3D地图文档（服务地址，配置参数）
            landscapeLayer = m3dLayer.append(`${protocol}://${ip}:${port}/igs/rest/g3d/钻孔分层点_Sur_000_Ent`, {
                autoReset: false,
                maximumScreenSpaceError: 8,
                loaded: function (layer) {
                    //清除开挖
                    if (dynaCut) {
                        webGlobe.deleteDynamicCutting(dynaCut);
                    }
                    //开挖面设置,这五个面分别表示前后左右，底面，其中底面用于控制开挖深度
                    var planes = [
                        new Cesium.ClippingPlane(new Cesium.Cartesian3(1, 0.0, 0.0), -1500.0),
                        new Cesium.ClippingPlane(new Cesium.Cartesian3(-1, 0.0, 0.0), -1500.0),
                        new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 1, 0.0), -1500.0),
                        new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, -1, 0.0), -1500.0),
                        new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 0.0, -1), -1000.0)
                    ];
                    //初始化分析功能管理类
                    var analysisManager = new CesiumZondy.Manager.AnalysisManager({
                        viewer: webGlobe.viewer
                    });
                    //创建开挖分析实例
                    dynaCut = analysisManager.createExcavateAnalysis({
                        //图层信息
                        tileset: landscapeLayer[0],
                        //开挖面的形状
                        planes: planes,
                        //裁剪面材质
                        material: new Cesium.Color(0.2, 0.4, 0.3, 0.7),
                        //边界线颜色
                        edgeColor: new Cesium.Color(0.2, 0.4, 0.3, 0.7),
                        //边界线宽度
                        edgeWidth: 3,
                        //裁减法线方向，默认值为 false
                        unionClippingRegions: false,
                        //开挖坐标
                        longitude: 113.0451,
                        latitude: 30.0262,
                        height: 0
                    });
                    console.log("tileset",landscapeLayer[0]);
                    //analysisManager.startDynamicExcavate(dynaCut.planes[0], distance, planes, landscapeLayer[0].modelMatrix)
                    // 设置开挖的动态效果
                    dynaCut.planes[0].plane.plane = new Cesium.CallbackProperty(function (date) {
                        // console.log(planes);
                        for (var i = 0; i < planes.length; i++) {
                            if (i === planes.length - 1) {
                                var plane = planes[i];
                                plane.distance = distance;
                                Cesium.Plane.transform(plane, landscapeLayer[0].modelMatrix, new Cesium.ClippingPlane(Cesium.Cartesian3.UNIT_X, 0.0));
                            }
                        }
                    }, false);
                }
            });
        }

        function change() {
            distance = Number(document.getElementById('range').value);
        }
    </script>
</head>

<body onload="init()">
    <div id="GlobeView">
        <div class="message" style="left: 10px;">
            <span>
                <font>开挖深度：</font><input type="range" id="range" min="-500" max="50" value="0" oninput="change()" />
            </span>
        </div>
    </div>
</body>

</html>